package com.itheima.dao;

import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface ReportDao {

    @Select("select count(*) from t_member where regTime < STR_TO_DATE(#{endDate}, '%Y-%m-%d')")
    public Integer getMemberReport(@Param("endDate") String endDate);
    @Select("select * from t_setmeal")
    public List<Setmeal> getSetmeal();

    @Select("select count(*) from t_order where setmeal_id=#{setmealId}")
    public Integer getBySetmealIdOrderCount(Integer setmealId);

    //统计当天新增 会员数
    @Select("select count(*) from t_member where regTime = #{date}")
    public Integer getByNowDate(String date);
    // 获取总会员数
    @Select("select count(*) from t_setmeal")
    public Integer getSetmealCount();

    // 获取本周 的新增 会员数
    @Select("select count(*) from t_member where regTime > STR_TO_DATE(#{thisWeekNewMember}, '%Y-%m-%d')")
    public Integer getWeekNewMember(@Param("thisWeekNewMember") String thisWeekNewMember);
    // 获取本月新增 会员数
    @Select("select COUNT(*) from t_member where regTime between STR_TO_DATE(#{startDate}, '%Y-%m-%d') and STR_TO_DATE(#{endDate}, '%Y-%m-%d')")
    public Integer gettMonthNewMember(@Param("startDate") String startDate,@Param("endDate") String endDate);

    // 获取 今天预约数
    @Select("select count(*) from t_order where orderDate = #{date}")
    public Integer getTodayOrderNumber(String date);
    // 统计 今天到诊数
    @Select("select count(*) from t_order where orderDate = #{date} and orderStatus = '已到诊'" )
    public Integer getTodayVisitsNumber(String date);
    // 统计本月(周) 预约数
    @Select("select count(*) from t_order where orderDate > STR_TO_DATE(#{startDate}, '%Y-%m-%d')")
    public Integer getMonthOrderNumber(String startDate);
    //获取本月(周) 就诊数
    @Select("select count(*) from t_order where orderDate > STR_TO_DATE(#{startDate}, '%Y-%m-%d') and orderStatus = '已到诊'")
    public Integer getMonthVisitsNumber(String startDate);

    //查询前四条 热门的套餐(以预约数量作为热门标注)
    @Select("select s.name name,count(o.id) setmeal_count,COUNT(o.id)/(select count(*) from  t_order) proportion " +
            " from t_order o , t_setmeal s where  s.id = o.setmeal_id " +
            " group by s.name " +
            " order by setmeal_count desc " +
            " limit 0,4")
    public List<Map> findHotSetmeal();

}
